Skip to content

Commit 9c991ec

Browse files
committed
Add Temporal tests
This copies over the tests that previously existed in the tc39/proposal-temporal repository. For context, see thread starting at: tc39#3002 (comment) In service of tc39#3002
1 parent 10ad4c1 commit 9c991ec

File tree

2,765 files changed

+67827
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,765 files changed

+67827
-3
lines changed

harness/temporalHelpers.js

Lines changed: 1173 additions & 2 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar
6+
description: Tests that Temporal.Calendar meets the requirements for built-in objects
7+
info: |
8+
Unless specified otherwise, a built-in object that is callable as a function is a built-in
9+
function object with the characteristics described in 10.3. Unless specified otherwise, the
10+
[[Extensible]] internal slot of a built-in object initially has the value true.
11+
12+
Unless otherwise specified every built-in function and every built-in constructor has the
13+
Function prototype object [...] as the value of its [[Prototype]] internal slot.
14+
features: [Temporal]
15+
---*/
16+
17+
assert.sameValue(Object.isExtensible(Temporal.Calendar),
18+
true, "Built-in objects must be extensible.");
19+
20+
assert.sameValue(Object.prototype.toString.call(Temporal.Calendar),
21+
"[object Function]", "Object.prototype.toString");
22+
23+
assert.sameValue(Object.getPrototypeOf(Temporal.Calendar),
24+
Function.prototype, "prototype");
25+
26+
assert.sameValue(typeof Temporal.Calendar.prototype,
27+
"object", "prototype property");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar
6+
description: Temporal.Calendar constructor cannot be called as a function
7+
info: |
8+
1. If NewTarget is undefined, throw a TypeError exception.
9+
features: [Temporal]
10+
---*/
11+
12+
assert.throws(TypeError, () => Temporal.Calendar());
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Tests that Temporal.Calendar.from meets the requirements for built-in objects
7+
info: |
8+
Built-in functions that are not constructors do not have a "prototype" property unless
9+
otherwise specified in the description of a particular function.
10+
11+
Unless specified otherwise, a built-in object that is callable as a function is a built-in
12+
function object with the characteristics described in 10.3. Unless specified otherwise, the
13+
[[Extensible]] internal slot of a built-in object initially has the value true.
14+
15+
Unless otherwise specified every built-in function and every built-in constructor has the
16+
Function prototype object [...] as the value of its [[Prototype]] internal slot.
17+
features: [Temporal]
18+
---*/
19+
20+
assert.sameValue(Object.isExtensible(Temporal.Calendar.from),
21+
true, "Built-in objects must be extensible.");
22+
23+
assert.sameValue(Object.prototype.toString.call(Temporal.Calendar.from),
24+
"[object Function]", "Object.prototype.toString");
25+
26+
assert.sameValue(Object.getPrototypeOf(Temporal.Calendar.from),
27+
Function.prototype, "prototype");
28+
29+
assert.sameValue(Temporal.Calendar.from.hasOwnProperty("prototype"),
30+
false, "prototype property");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Converting objects to Temporal.Calendar
7+
features: [Temporal]
8+
---*/
9+
10+
assert.throws(RangeError, () => Temporal.Calendar.from({ calendar: "local" }));
11+
assert.throws(RangeError, () => Temporal.Calendar.from({ calendar: { calendar: "iso8601" } }));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Converting objects to Temporal.Calendar
7+
includes: [compareArray.js, temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
const expected = [
12+
"has outer.calendar",
13+
"get outer.calendar",
14+
"has inner.calendar",
15+
"get inner.toString",
16+
"call inner.toString",
17+
];
18+
const actual = [];
19+
const calendar = new Proxy({}, {
20+
has(t, p) {
21+
actual.push(`has outer.${p}`);
22+
return true;
23+
},
24+
get(t, p) {
25+
actual.push(`get outer.${p}`);
26+
return new Proxy(TemporalHelpers.toPrimitiveObserver(actual, "iso8601", "inner"), {
27+
has(t, p) {
28+
actual.push(`has inner.${p}`);
29+
return true;
30+
},
31+
get(t, p) {
32+
return t[p];
33+
},
34+
});
35+
},
36+
});
37+
const result = Temporal.Calendar.from(calendar);
38+
assert.sameValue(result.id, "iso8601");
39+
assert.compareArray(actual, expected);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Converting objects to Temporal.Calendar
7+
features: [Temporal]
8+
---*/
9+
10+
const cal = new Temporal.Calendar("iso8601");
11+
const calFromObject = Temporal.Calendar.from({ calendar: cal });
12+
assert(calFromObject instanceof Temporal.Calendar);
13+
assert.sameValue(calFromObject.id, "iso8601");
14+
15+
const calFromString = Temporal.Calendar.from({ calendar: "iso8601" });
16+
assert(calFromString instanceof Temporal.Calendar);
17+
assert.sameValue(calFromString.id, "iso8601");
18+
19+
const custom = { id: "custom-calendar" };
20+
assert.sameValue(Temporal.Calendar.from({ calendar: custom }), custom);
21+
assert.sameValue(Temporal.Calendar.from(custom), custom);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Calendar.from should support iso8601.
7+
features: [Temporal]
8+
---*/
9+
10+
const tests = [
11+
"iso8601",
12+
"1994-11-05T08:15:30-05:00",
13+
];
14+
15+
for (const item of tests) {
16+
const calendar = Temporal.Calendar.from(item);
17+
assert(calendar instanceof Temporal.Calendar);
18+
assert.sameValue(calendar.id, "iso8601");
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: from() throws if the argument is not a built-in calendar name.
7+
features: [Temporal]
8+
---*/
9+
10+
const tests = [
11+
"local",
12+
"iso-8601",
13+
"[u-ca=iso8601]",
14+
"invalid-calendar",
15+
];
16+
17+
for (const item of tests) {
18+
assert.throws(RangeError, () => Temporal.Calendar.from(item));
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
7+
info: |
8+
sec-temporal.calendar.from step 1:
9+
1. Return ? ToTemporalCalendar(_item_).
10+
sec-temporal-totemporalcalendar step 1.a:
11+
a. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
12+
i. Return _temporalCalendarLike_.[[Calendar]].
13+
includes: [compareArray.js, temporalHelpers.js]
14+
features: [Temporal]
15+
---*/
16+
17+
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
18+
const newCalendar = Temporal.Calendar.from(temporalObject);
19+
assert.sameValue(newCalendar, calendar, "calendar object retrieved from internal slot");
20+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Temporal.Calendar.from.length is 1
7+
info: |
8+
Every built-in function object, including constructors, has a "length" property whose value is
9+
an integer. Unless otherwise specified, this value is equal to the largest number of named
10+
arguments shown in the subclause headings for the function description. Optional parameters
11+
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
12+
«...name») are not included in the default argument count.
13+
14+
Unless otherwise specified, the "length" property of a built-in function object has the
15+
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
16+
includes: [propertyHelper.js]
17+
features: [Temporal]
18+
---*/
19+
20+
verifyProperty(Temporal.Calendar.from, "length", {
21+
value: 1,
22+
writable: false,
23+
enumerable: false,
24+
configurable: true,
25+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Temporal.Calendar.from.name is "from"
7+
info: |
8+
Every built-in function object, including constructors, that is not identified as an anonymous
9+
function has a "name" property whose value is a String. Unless otherwise specified, this value
10+
is the name that is given to the function in this specification.
11+
12+
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
13+
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
14+
includes: [propertyHelper.js]
15+
features: [Temporal]
16+
---*/
17+
18+
verifyProperty(Temporal.Calendar.from, "name", {
19+
value: "from",
20+
writable: false,
21+
enumerable: false,
22+
configurable: true,
23+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: Temporal.Calendar.from does not implement [[Construct]], is not new-able
7+
info: |
8+
Built-in function objects that are not identified as constructors do not implement the
9+
[[Construct]] internal method unless otherwise specified in the description of a particular
10+
function.
11+
includes: [isConstructor.js]
12+
features: [Reflect.construct, Temporal]
13+
---*/
14+
15+
assert.throws(TypeError, () => {
16+
new Temporal.Calendar.from();
17+
}, "Calling as constructor");
18+
19+
assert.sameValue(isConstructor(Temporal.Calendar.from), false,
20+
"isConstructor(Temporal.Calendar.from)");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: The "from" property of Temporal.Calendar
7+
includes: [propertyHelper.js]
8+
features: [Temporal]
9+
---*/
10+
11+
assert.sameValue(
12+
typeof Temporal.Calendar.from,
13+
"function",
14+
"`typeof Calendar.from` is `function`"
15+
);
16+
17+
verifyProperty(Temporal.Calendar, "from", {
18+
writable: true,
19+
enumerable: false,
20+
configurable: true,
21+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar.from
6+
description: The receiver is never called when calling from()
7+
includes: [temporalHelpers.js]
8+
features: [Temporal]
9+
---*/
10+
11+
TemporalHelpers.checkSubclassingIgnoredStatic(
12+
Temporal.Calendar,
13+
"from",
14+
["iso8601"],
15+
(result) => {
16+
assert.sameValue(result.id, "iso8601", "id property of result");
17+
assert.sameValue(result.toString(), "iso8601", "toString() of result");
18+
},
19+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar
6+
description: Temporal.Calendar.length is 1
7+
info: |
8+
Every built-in function object, including constructors, has a "length" property whose value is
9+
an integer. Unless otherwise specified, this value is equal to the largest number of named
10+
arguments shown in the subclause headings for the function description. Optional parameters
11+
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
12+
«...name») are not included in the default argument count.
13+
14+
Unless otherwise specified, the "length" property of a built-in function object has the
15+
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
16+
includes: [propertyHelper.js]
17+
features: [Temporal]
18+
---*/
19+
20+
verifyProperty(Temporal.Calendar, "length", {
21+
value: 1,
22+
writable: false,
23+
enumerable: false,
24+
configurable: true,
25+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar
6+
description: RangeError thrown when constructor invoked with no argument
7+
features: [Temporal]
8+
---*/
9+
10+
assert.throws(RangeError, () => new Temporal.Calendar());
11+
assert.throws(RangeError, () => new Temporal.Calendar(undefined));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.calendar
6+
description: Temporal.Calendar.name is "Calendar"
7+
info: |
8+
Every built-in function object, including constructors, that is not identified as an anonymous
9+
function has a "name" property whose value is a String. Unless otherwise specified, this value
10+
is the name that is given to the function in this specification.
11+
12+
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
13+
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
14+
includes: [propertyHelper.js]
15+
features: [Temporal]
16+
---*/
17+
18+
verifyProperty(Temporal.Calendar, "name", {
19+
value: "Calendar",
20+
writable: false,
21+
enumerable: false,
22+
configurable: true,
23+
});

0 commit comments

Comments
 (0)